import type { StudentClassResp } from './class'
import http from '@/utils/http'

/** 班级查询请求 */
export interface ShopClassQuery {
  subject: string
  keyword?: string
  campusId?: string
  grade: string
  classYear?: number
  term?: string
  classCategory?: number
  studentId: string
  arrangeTemplateId?: string
  timeTemplateId?: string
  leadTeacherId?: string
}

/** 选课班级信息 */
export interface ShopClassResp extends StudentClassResp {

}

// 添加购物车请求参数
export interface CartItemAddReq {
  studentId: string
  classId: string
  lessonIndexes: number[]
}

export interface CartItem {
  id: string
  studentId: string
  classId: string
  lessonIndexes: number[]
  classInfo: ShopClassResp
}

/** 优惠券 */
// 查询
export interface ParentCouponQuery {
  couponStatus?: number
  orderId?: string
}

export interface Coupon {
  id: string
  couponTemplateId: string
  orderId: string
  receiveType: string
  receiveTime: string
  useTime?: string
  couponStatus: number
}

export interface CouponTemplate {
  id: string
  name: string
  image: string
  discountType: string
  discountAmount: number
  maxDiscountAmount: number
  thresholdAmount: number
  classIdLimit: string[]
  classCategoryLimit: string[]
  classSubjectLimit: string[]
  classGradeLimit: string[]
  classTermLimit: string[]
  classYearLimit: string[]
  stackingUseEnabled: boolean
  receiveLimitCount: number
  validType: string
  startValidTime: string
  endValidTime: string
  validDays: number
  status: number
  description?: string
}

export interface CouponDetail {
  id: string
  couponTemplateId: string
  orderId?: string
  receiveType: string
  receiveTime: string
  useTime?: string
  couponStatus: number
  startValidTime: string
  endValidTime: string
  template: CouponTemplate
}

// 搜索购课班级
export function searchShopClass(req: ShopClassQuery) {
  return http.get<Page<ShopClassResp>>(`/p/shop/class/search`, req)
}

// 查询购课班级列表（用于转班调课）
export function getShopClassList(req: ShopClassQuery) {
  return http.get<ShopClassResp[]>(`/p/shop/class/list`, req)
}

// 查询购课班级详情
export function getShopClassDetail(classId: string) {
  return http.get<ShopClassResp>(`/p/shop/class/detail/${classId}`)
}

// 加入购物车
export function addCartItem(req: CartItemAddReq) {
  return http.post(`/p/shop/cart/add`, req)
}

// 删除购物车
export function removeCartItem(id: string) {
  return http.post(`/p/shop/cart/remove/${id}`)
}

// 查询购物车
export function getCartItemList(studentId: string) {
  return http.get<CartItem[]>(`/p/shop/cart/get/${studentId}`)
}

// 获取购物车数量
export function getCardItemCount(studentId: string) {
  return http.get(`/p/shop/cart/count/${studentId}`)
}

// 查询优惠券
export function getCouponList(query: ParentCouponQuery) {
  return http.get<CouponDetail[]>(`/p/shop/coupon/list`, query)
}
